import java.awt.*;
import javax.swing.*;

import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.imageio.ImageIO;
import javax.swing.JPanel;

public class Saron extends JApplet
{
    public void init()
    {
	System.out.println("Client Saron 0.0.1 as Java");
	
	JFrame frame = new JFrame("Saron Java Client");
	frame.setSize(200, 200);
	sJPanel panel = new sJPanel();

	frame.add(panel);

	try
	{
	    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	}
	catch (SecurityException e)
	{
	    System.out.println("WARNING: Nie udało się ustawić zakończenie programu przy zamknieciu okna ");
	}
	frame.setLocation(0, 0);
	frame.setSize(Toolkit.getDefaultToolkit().getScreenSize());
	frame.setVisible(true);
	frame.repaint();
    }
}

class sJPanel extends JPanel
{
    public sJPanel()
    {
	this.setLayout(null);

	this.add(new sTopPanel(50));
	this.add(new sDesktop(50));
    }
}

class sTopPanel extends JPanel
{
    public sTopPanel(int height)
    {
	this.setLayout(null);
	this.setBackground(new Color(0, 255, 0));
	this.setBounds(0, 0, Toolkit.getDefaultToolkit().getScreenSize().width, height);
    }
}

class sDesktop extends JPanel
{
    private BufferedImage image;

    public sDesktop(int height)
    {
	this.setLayout(null);
	this.setBackground(new Color(220, 220, 255));
	this.setBounds(0, height, Toolkit.getDefaultToolkit().getScreenSize().width, Toolkit.getDefaultToolkit().getScreenSize().height-height);
	
	JLabel labHello = new JLabel("Witaj w Saron v0.0.0 pre-alpha");
	labHello.setBounds(500, 200, 400, 12);
	labHello.setFont(new Font("Arial", Font.PLAIN, 12));
	labHello.setForeground(new Color(255, 255, 255));
	this.add(labHello);

	String nazwa = "desktop_background.jpg";
	Image obraz = Toolkit.getDefaultToolkit().getImage(nazwa);

	try
	{
	    this.image = ImageIO.read(new File("desktop_background.jpg"));
	}
	catch (IOException ex)
	{
            System.out.println("WARNING: Błąd przy wczytywania tła: desktop_background.jpg");
	}

	JButton butLive = new JButton("Wersja Live");
	butLive.setBounds(600, 250, 150, 30);
	this.add(butLive);
    }

    public void paintComponent(Graphics g)
    {
        g.drawImage(image, 500, 200, null); 
    }
}